package com.ybdz.scanner.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ybdz.scanner.R;
import com.ybdz.scanner.bean.DepositHistoryBean;
import com.ybdz.scanner.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: LookDepositAdapter
 * @author: zhao
 * @Description: 查看入库历史的adapter
 * @date 2018/1/20 15:16
 */
public class LookDepositAdapter extends RecyclerView.Adapter {

    private List<DepositHistoryBean> mList = new ArrayList<>();

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(UIUtils.getContext()).inflate(R.layout.item_recycleview, parent, false);
        return new LookDepositViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        LookDepositViewHolder lookDepositViewHolder = (LookDepositViewHolder) holder;
        for (int i = 0; i < mList.size(); i++) {
            lookDepositViewHolder.mTvName.setText(mList.get(i).getName().substring(3));
            lookDepositViewHolder.mTvWeight.setText(String.valueOf((mList.get(i).getWeight())/1000));
            lookDepositViewHolder.mTvConformity.setText(mList.get(i).getIsQualified());
        }
    }

    @Override
    public int getItemCount() {
       return mList.size() == 0?0:mList.size();
    }

    public void setData(List<DepositHistoryBean> list) {
        this.mList = list;
    }


    static class LookDepositViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_weight)
        TextView mTvWeight;
        @BindView(R.id.tv_conformity)
        TextView mTvConformity;

        LookDepositViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
